<template>
  <div class="two">
    <!-- <h2>菜单管理</h2> -->
    <el-card>
      <el-button type="primary" plain @click="addfn">+新增</el-button>
      <div class="one">
        <el-table
          :data="tableData"
          style="width: 100%;margin-bottom: 20px;"
          row-key="id"
          border
          default-expand-all
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <el-table-column
            prop="title"
            label="菜单名称"
            sortable
            width="180"
          />
          <el-table-column
            prop="path"
            label="菜单地址"
            sortable
            width="180"
          />
          <el-table-column
            prop="mark"
            label="权限标识"
          />
          <el-table-column
            prop="icon"
            label="图标"
            width="166"
          >
            <template #default="{row}">
              <SvgIcon :icon-class="row.icon" />
            </template>
          </el-table-column>
          <el-table-column
            prop="component"
            label="组件路径"
          />
          <el-table-column
            prop="type"
            label="类型"
          >
            <template #default="{row}">
              <!-- {{ row.type === 1 ? '菜单' : '按钮' }} -->
              <el-button v-if="row.type === 1" type="primary" size="small" plain>菜单</el-button>
              <el-button v-else type="warning" size="small" plain>按钮</el-button>
            </template>
          </el-table-column>
          <el-table-column
            prop="is_show"
            label="是否显示"
          >
            <el-switch
              v-model="formDate.isShow"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-value="1"
              inactive-value="0"
            />
          </el-table-column>
          <el-table-column
            label="操作"
            width="221"
          >
            <template #default="{row}">
              <el-button type="primary" icon="el-icon-edit" circle @click="Updata(row.id)" />
              <el-button type="warning" icon="el-icon-plus" circle @click="addto(row.id)" />
              <el-button type="danger" icon="el-icon-delete" circle @click="delfn(row.id)" />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <AddManageVue ref="addtoForm" :show-dialog.sync="showDialog" />
  </div>
</template>

<script>
import { getsystemAPI, deletesystemAPI, updataAddAPi } from '@/api/system'
import AddManageVue from './component/add-manage.vue'
import SvgIcon from '@/components/SvgIcon'
export default {
  name: 'Management',
  components: {
    AddManageVue,
    SvgIcon
  },
  data() {
    return {
      tableData: [],
      formDate: {
        isShow: ''
      },
      showDialog: false
    }
  },
  created() {
    this.Userlist()
  },
  methods: {
    async Userlist() {
      const res = await getsystemAPI()
      console.log(res)
      this.tableData = res.data
    },
    delfn(id) {
      console.log(id)
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await deletesystemAPI(id)
        console.log(res)
        this.$message.success('删除成功')
        this.Userlist()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    addfn() {
      this.showDialog = true
    },
    addto(id) {
      this.showDialog = true
      this.$refs.addtoForm.formData.pid = id
    },
    async Updata(id) {
      this.showDialog = true
      const res = await updataAddAPi(id)
      this.$refs.addtoForm.formData = res.data
    }
  }
}
</script>

<style scoped>
 .two{
   padding: 50px 10px 0 10px;
 }
 .one{
  padding-top: 20px;
 }
</style>
